package com.rdxer.api;

import com.rdxer.service.InitialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@CrossOrigin
@Controller
public class InitApi {

    @Autowired
    InitialService initialService;


    @GetMapping("/init")
    ModelAndView init() {

        initialService.check();

        ModelAndView modelAndView = new ModelAndView();

        modelAndView.setViewName("init");

        return modelAndView;
    }

    @Transactional
    @PostMapping("/init")
    ModelAndView execInit(String username, String password, String displayName) {


        initialService.check();

        initialService.setUpDeptRoleInfo();

        initialService.addSuperAdmin(username, password, displayName);



        ModelAndView modelAndView = new ModelAndView();

        modelAndView.setViewName("initend");

        return modelAndView;
    }


}
